package br.com.dips.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Transient;

import br.com.dips.enums.Situacao;

@Entity
@NamedQueries({
	@NamedQuery(name="Organizacao.findById", query="select org from Organizacao org where org.id =:id"),
	@NamedQuery(name="Organizacao.findBySituacao", query="select org from Organizacao org where org.situacao = :situacao"),
	@NamedQuery(name="Organizacao.findAll", query="select org from Organizacao org")
})
public class Organizacao implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id 
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;

	@Column(name="nome")
	private String nome;

	@Column(name="nome_reduzido")
	private String nomeReduzido;
	
	@Column(name="situacao")
	private Character situacao;
	
	@Transient
	private List<OrganizacaoCliente> clientes;
	
	public Organizacao() {
		this.situacao = Situacao.ATIVO.getCodigo();
	}
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getNomeReduzido() {
		return nomeReduzido;
	}

	public void setNomeReduzido(String nomeReduzido) {
		this.nomeReduzido = nomeReduzido;
	}

	public Situacao getSituacao() {
		return Situacao.fromCodigo(this.situacao);
	}

	public void setSituacao(Situacao situacao) {
		this.situacao = situacao.getCodigo();
	}
	
	public List<OrganizacaoCliente> getClientes() {
		return clientes;
	}

	public void setClientes(List<OrganizacaoCliente> clientes) {
		this.clientes = clientes;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Organizacao other = (Organizacao) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	

}
